Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make.js: trim excess whitespaces from CFLAGS and LDFLAGS #1251

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yojoe
Copy link

@yojoe yojoe commented Apr 21, 2023

Excess whitespaces in the CFLAGS and LDFLAGS variables cause gcc compilation errors like aarch64-unknown-linux-gnu-gcc: error: No such file or directory. This is hard to debug and happens because the .split(' ') function will create empty gcc arguments, if there are any excess whitespaces in the CFLAGS and LDFLAGS environment variables. This can happen when cross-compiling using a 3rd party toolchain, which manipulates/sets the CFLAGS/LDFLAGS variables and accidentally/carelessly puts to many whitespaces in these flags. We better trim any whitespaces from the beginning and end of CFLAGS/LDFLAGS strings and match consecutive whitespaces within the strings via a regex instead, to avoid these nasty and hard to spot compilation errors.

Excess whitespaces in the CFLAGS and LDFLAGS variables cause `gcc` compilation errors like `aarch64-unknown-linux-gnu-gcc: error: No such file or directory`. This is hard to debug and happens because the `.split(' ')` function will create empty `gcc` arguments, if there are any excess whitespaces in the CFLAGS and LDFLAGS environment variables. This can happen when cross-compiling using a 3rd party toolchain, which manipulates/sets the CFLAGS/LDFLAGS variables and accidentally/carelessly puts to many whitespaces in these flags. We better `trim` any whitespaces from the beginning and end of CFLAGS/LDFLAGS strings and match consecutive whitespaces within the strings via a regex instead, to avoid these nasty and hard to spot compilation errors.
@webbdays
Copy link

Can i work on this?
this code base is new to me.
Please guide me to place in code where we parse the flags.

@@ -144,7 +144,7 @@ Builder.configure({
// with NEON on the BBB, or want to set -Os (OpenWrt)
// Allow -O0 so while debugging all variables are present.
if (CFLAGS) {
var cflags = CFLAGS.split(' ');
var cflags = CFLAGS.split.trim().split(/\s+/);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CFLAGS.split.trim().split(/\s+/); won't do what you're expecting. I think you want CFLAGS.trim().split(/\s+/);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I made this comment over 1 year ago but it got sucked up into a "code review" and so you never saw it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants